package com.arcvideo.acsconnect.ui.screen;

import android.content.Context;
import android.view.SurfaceView;

import com.arcvideo.acsconnect.widget.UserHeadInfoLayout;
import com.framework.core.utils.AppUtil;

import java.util.List;

/**
 * @author shenmengchao
 * @version 1.0.0
 * @date 2018/10/10
 * @description
 */

public abstract class Screen {

    protected Context context;
    protected int number;
    protected List<SurfaceView> surfaceViewList;
    protected List<UserHeadInfoLayout> userHeadInfoLayoutList;
    protected int windowWidth;
    protected int windowHeight;

    public static Screen create(Context context,
                                int number,
                                List<SurfaceView> surfaceViewList,
                                List<UserHeadInfoLayout> userHeadInfoLayoutList) {
        if (number <= 0) {
            throw new RuntimeException("number must > 0");
        }
        if (null == surfaceViewList || surfaceViewList.size() < number) {
            throw new RuntimeException("surfaceViewList size must > number");
        }
        if (null == userHeadInfoLayoutList || userHeadInfoLayoutList.size() < number) {
            throw new RuntimeException("userHeadInfoLayoutList size must > number");
        }
        Screen screen = null;
        switch (number) {
            case 1:
                screen = new OneScreen();
                break;
            case 2:
                screen = new TwoScreen();
                break;
            case 3:
                screen = new ThreeScreen();
                break;
            case 4:
                screen = new FourScreen();
                break;
            default:
                break;
        }
        if (null != screen) {
            screen.setContext(context);
            screen.setNumber(number);
            screen.setSurfaceViewList(surfaceViewList);
            screen.setUserHeadInfoLayoutList(userHeadInfoLayoutList);
            screen.setWindowWidth(AppUtil.getWindowWidth(context));
            screen.setWindowHeight(AppUtil.getWindowHeight(context));
            return screen;
        }
        throw new RuntimeException("no suitable screen");
    }

    public abstract void refresh();

    public void setContext(Context context) {
        this.context = context;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public void setSurfaceViewList(List<SurfaceView> surfaceViewList) {
        this.surfaceViewList = surfaceViewList;
    }

    public void setUserHeadInfoLayoutList(List<UserHeadInfoLayout> userHeadInfoLayoutList) {
        this.userHeadInfoLayoutList = userHeadInfoLayoutList;
    }

    public void setWindowWidth(int windowWidth) {
        this.windowWidth = windowWidth;
    }

    public void setWindowHeight(int windowHeight) {
        this.windowHeight = windowHeight;
    }
}
